﻿using System.Collections;
using System.Collections.Generic;
using PEProtocol;
using UnityEngine;
using UnityEngine.UI;

/**
 * 购买交易窗口
 */
public class BuyWnd : WindowRoot{

    private int buyType; //0：体力，1：金币

    public Text txtInfo;

    public void SetBuyType(int type){
        buyType = type;
    }
    
    protected override void InitWnd(){
        base.InitWnd();
        RefreshUI();
    }

    private void RefreshUI(){
        switch (buyType){
            case 0:
                //体力
                txtInfo.text = "是否花费" + Constants.Color("10钻石", TxtColor.Red) + "购买" + Constants.Color("100体力", TxtColor.Green) + "?";
                break;
            case 1:
                //金币
                txtInfo.text = "是否花费" + Constants.Color("10钻石", TxtColor.Red) + "购买" + Constants.Color("1000金币", TxtColor.Green) + "?";
                break;
        }
    }

    public void ClickSureBtn(){
        audioSvc.PlayUIMusic(Constants.UIClickBtn);
        
        //发送网络购买消息
        GameMsg msg = new GameMsg{
            cmd = (int)CMD.ReqBuy,
            reqBuy = new ReqBuy{
                type = buyType,
                cost = 10
            }
        };

        netSvc.SendMsg(msg);
    }

    public void ClickCloseBtn(){
        audioSvc.PlayUIMusic(Constants.UIClickBtn);
        SetWndState(false);
    }
}